package com.alibaba.spider.controller;

import com.alibaba.spider.model.RespBean;
import com.alibaba.spider.service.CrawlService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author fangyu
 * @version v1.0.0
 * @date 2020/10/4 5:34 下午
 */
@Slf4j
@RestController
public class ApiController {
    @Autowired
    private CrawlService crawlService;

    @GetMapping({"/alibaba"})
    public RespBean getAliBaBa(@RequestParam String url) {
        List<String> result = crawlService.getResult(url);
        return RespBean.ok("", result);
    }

    @GetMapping({"/key"})
    public RespBean getAllKey(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int pageSize) {
        return RespBean.ok("待开发...");
    }

    @PostMapping({"/save"})
    public RespBean saveKey(@RequestParam String key, @RequestParam String word) {
        log.info("key ==> {}", key);
        return RespBean.ok("待开发...");
    }

    @PostMapping({"/delete/{key}"})
    public RespBean deleteKey(@PathVariable String key) {
        return RespBean.ok("待开发...");
    }

    @PutMapping({"/update/{id}"})
    public RespBean updateStatus(@PathVariable Integer id) {
        return RespBean.ok("待开发...");
    }
}
